package ensemble.samples.controls

import ensemble.DynamicSizeSample
import javafx.scene.paint.Color
import net.oschina.oldpig.snout.FxBuilder
import javafx.scene.control.{Button, ColorPicker}
import javafx.geometry.Pos
import javafx.scene.text.{Font, Text => FxText}

class ColorPickerSampleS extends DynamicSizeSample{
  import FxBuilder._
  val picker = is[ColorPicker]
  val coloredText = is[FxText]
  val coloredButton = is[Button]

  def createRGBString(c: Color) = s"-fx-base: rgb(${c.getRed * 255},${c.getGreen * 255},${c.getBlue * 255});"

  def content =
    vBox(alignment := Pos.CENTER, spacing := 150, padding := (0, 0, 120, 0)){
      toolBar(){
        colorPicker(color := Color.GRAY) as picker
      }
      vBox(alignment := Pos.CENTER, spacing := 20){
        fxText(text := "Colors", font := new Font(53), fill := picker.getValue) as coloredText
        button(text := "Colored Control", style := createRGBString(picker.getValue), onAction := { e =>
          coloredText.setFill(picker.getValue)
          coloredButton.setStyle(createRGBString(picker.getValue))
        }) as coloredButton
      }
    }
}
